<?php
if (! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * 控制器基类 重写
 * User: zyw
 * Date: 16/7/26
 * Time: 下午2:13
 */

class MY_Controller extends CI_Controller{

    public function __construct(){
        parent::__construct();

        $flag = $this->checkLogin();//检测登陆状态
        if(!$flag){
            //跳转到登陆页面
            header("Location:index.php?c=login&m=do_login");
        }
        $status = $this->checkPermission();//检测权限状态
        if(!$status){
            //提示权限不够
        }
    }

    /**
     * 检测登陆状态
     * @param $data
     * @return bool
     */
    private function checkLogin(){
        $authlessActions = $this->config->config['authlessActions'];
        $action = $this->router->method;
        //检测免登陆的action
        if(in_array($action,$authlessActions)){
            return true;
        }
        $userData = getLoginUser();
        if(empty($userData) || empty($userData['uid'])){
            return false;
        }
        //首次登陆

        return true;
    }

    /**
     * 检测权限
     * @return bool
     */
    private function checkPermission(){

        return true;
    }
}